#ifndef ARRAY_LIST_H
#define ARRAY_LIST_H
#include <vector>
#include <iostream>

template<typename T>
class ArrayList
{
public:
    ArrayList();
    void append(const T& element);
    void printAll() const;
private:
    void grow();
    size_t len_;
    size_t capacity_;
    T* elements_;
};

template<typename T>
ArrayList<T>::ArrayList()
  : len_(0),
    capacity_(3)
{
    elements_ = new T[3];
}

template<typename T>
void ArrayList<T>::grow()
{
    capacity_ *= 2;
    T* temp = elements_;
    elements_ = new T[capacity_];
    std::copy(temp, temp + len_, elements_);
}

template<typename T>
void ArrayList<T>::append(const T &element)
{
    if (len_ >= capacity_)
        grow();
    elements_[len_++] = element;
}

template<typename T>
void ArrayList<T>::printAll() const
{
    for (int index = 0; index < len_; index++)
        std::cout << elements_[index] << ' ';
    std::cout << std::endl;
}

#endif

